<?php
namespace App\Http\Controllers;

use App\Models\BannerModel;
use App\Models\ContentModel;
use App\Models\KefuModel;
use App\Models\WordModel;

class IndexController extends Controller
{
    function index($id){
        $row=KefuModel::where('id',$id)->where('status',1)->first();
        if(!$row){
            abort(404);
        }
        $row->show_times+=1;
        $row->save();
        $url=url('storage/'.$row->image);
        return view('show',['image'=>$url,'id'=>$row->id,'name'=>$row->name]);
    }

    function jump($id){
        $row=KefuModel::where('id',$id)->where('status',1)->first();
        if(!$row){
            abort(404);
        }
        $row->click_times+=1;
        $row->save();
        return redirect($row->url);
    }

    function abav(){
        $banners=BannerModel::where('status',1)->pluck('image')->toArray();
        $words=WordModel::where('status',1)->inRandomOrder()->limit(5)->pluck('contents')->toArray();
        $content=ContentModel::where('status',1)->inRandomOrder()->limit(2)->pluck('contents')->toArray();
        return [
            'banner'=>$banners,
            'search_words'=>$words,
            'contents'=>$content,
//            'url'=>''
        ];
    }
}
